package com.foreknow.elm.po;

import com.mysql.jdbc.Connection;

import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class tet {


    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = (Connection) DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/elm?characterEncoding=UTF-8","root",
                    "root");
            PreparedStatement preparedStatement = connection.prepareStatement("SELECT SUM(c.quantity*f.foodPrice) FROM cart c,food f WHERE c.foodId = f.foodId AND c.userId = ?");
           preparedStatement.setObject(1,"18240394122");
            ResultSet resultSet = preparedStatement.executeQuery();
            while (resultSet.next()){
            int anInt = resultSet.getInt(1);
            System.out.println(anInt);}


            resultSet.close();
            preparedStatement.close();
            connection.close();


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
        }
    }
}
